﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using NetBay.Core.BusinessEntities;
using Telerik.Windows.Controls;

namespace Rio.Framework.Pages.Controls
{
    public class FolderAlertColumn : GridViewBoundColumnBase
    {
        public List<Folder> Folders { get; set; }
        public ICommand OpenAlertWindowCommand { get; set; }

        public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            Dictionary<string, object> folder = (Dictionary<string, object>)dataItem;
            if (folder.ContainsKey("NbAlert"))
            {
                int alertsCount = Convert.ToInt32(folder["NbAlert"]);

                if (alertsCount > 0)
                {
                    return new RadButton
                               {
                                   Content = new Image
                                                 {
                                                     Source =
                                                         new BitmapImage(
                                                         new Uri(
                                                             "/Rio.Framework.Pages;component/Assets/Images/AlertFolder.png",
                                                             UriKind.Relative)),
                                                 },
                                   Command = OpenAlertWindowCommand,
                                   CommandParameter = Convert.ToInt64(folder["Identifier"]),
                                   Height = 32,
                                   Width = 32
                               };
                }
                return null;

                //return base.CreateCellElement(cell, dataItem);
            }

            return base.CreateCellElement(cell, dataItem);
        }
    }
}
